package com.gperp.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gperp.common.GPResult;
import com.gperp.common.StringUtils;
import com.gperp.pojo.AsUser;
import com.gperp.service.AsUserService;

@Controller
public class AsUserController {
	@Resource
	private AsUserService asUserService;

	@RequestMapping(value="getLogin",method=RequestMethod.POST)
	@CrossOrigin
	@ResponseBody
	public AsUser login(String userCode,String userPassword,HttpSession session){
		/*return asUserService.getUserLogin(userCode, userPassword);*/
		AsUser user = asUserService.getUserLogin(userCode, userPassword);
		session.setAttribute("user", user);
		return user;
	}
	
	@RequestMapping(value="userListBy",method=RequestMethod.GET)
	@CrossOrigin
	@ResponseBody
	public Map<String,Object> userListBy(@RequestParam(defaultValue="1")Integer pageNo,String username,Integer isstart,Integer roleid){
		return asUserService.queryList(pageNo,StringUtils.getGetString(username),roleid,isstart);
	}
	
	@RequestMapping(value="deleteById",method=RequestMethod.GET)
	@CrossOrigin
	@ResponseBody
	public GPResult deleteById(String userIds){
		return asUserService.deleteById(userIds);
	}
	
	@RequestMapping(value="checkCode",method=RequestMethod.GET)
	@CrossOrigin
	@ResponseBody
	public GPResult checkCode(String usercode){
		return asUserService.checkCode(StringUtils.getGetString(usercode));
	}
	
	@RequestMapping(value="updatePass",method=RequestMethod.POST)
	@CrossOrigin
	@ResponseBody
	public GPResult updatePass(AsUser user){
		return asUserService.updateUser(user);
	}
	
	@RequestMapping(value="saveUser",method=RequestMethod.POST)
	@CrossOrigin
	@ResponseBody
	public GPResult saveUser(AsUser user){
		return asUserService.saveUser(user);
	}
	
	@RequestMapping(value="updateUser",method=RequestMethod.POST)
	@CrossOrigin
	@ResponseBody
	public GPResult updateUser(AsUser user){
		return asUserService.updateUser(user);
	}
	
	@RequestMapping(value="queryUserByID",method=RequestMethod.GET)
	@CrossOrigin
	@ResponseBody
	public AsUser queryUserByID(Long id){
		return asUserService.queryUserByID(id);
	}
	
	@RequestMapping(value="queryUserAll",method=RequestMethod.GET)
	@CrossOrigin
	@ResponseBody
	public List<AsUser> queryUserAll(){
		return asUserService.queryUserAll();
	}
	
	@RequestMapping(value="checkFace",method=RequestMethod.POST) //检查人脸在人脸库中是否匹配
	@CrossOrigin
	@ResponseBody
	public String checkFace(String img){
		return asUserService.checkFace(img);
	}
	
	@RequestMapping(value="saveFace",method=RequestMethod.POST) //把人脸和用户id保存在人脸库中
	@CrossOrigin
	@ResponseBody
	public String saveFace(String img,String id){
		return asUserService.saveFace(img,id);
	}
	
	@RequestMapping(value="faceExists",method=RequestMethod.GET) //把人脸和用户id保存在人脸库中
	@CrossOrigin
	@ResponseBody
	public String faceExists(String id){
		return asUserService.faceExists(id);
	}
}
